home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATETIME.SWG / 0049_Calculate Days between two Dates.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  69 lines

  1. {
  2. Allright... I checked around a lot of DATE and TIME routines, and came up
  3. with this, taken from about three different routines. This routine works,
  4. as far as I know, and I've implemented it successfully into my own code.
  5. If anyone knows that this routine has a bug in it, please let me know.
  6.  
  7. This procedure uses the Julian calander mathmatical equasions to convert
  8. two dates and give the # of days inbetween. If anyone knows a faster way
  9. of writing this procedure, please let me know.
  10. }
  11.  
  12. type
  13.   string80=string[80];
  14.  
  15. var
  16.   _retval:integer;
  17.  
  18. procedure check_date(stream1,stream2:string80);
  19. var
  20.   internal1,internal2:longint;
  21.   JNUM:real;
  22.   cd,month,day,year: integer;
  23.   out:string[25];
  24.  
  25.     function Jul( mo, da, yr: integer): real;
  26.     var
  27.       i, j, k, j2, ju: real;
  28.     begin
  29.          i := yr;     j := mo;     k := da;
  30.          j2 := int( (j - 14)/12 );
  31.          ju := k - 32075 + int(1461 * ( i + 4800 + j2 ) / 4 );
  32.          ju := ju + int( 367 * (j - 2 - j2 * 12) / 12);
  33.          ju := ju - int(3 * int( (i + 4900 + j2) / 100) / 4);
  34.          Jul := ju;
  35.     end;
  36.  
  37. begin
  38.   out:=copy(stream1,1,2);
  39.   if copy(out,1,1)='0' then delete(out,1,1);
  40.   val(out,month,cd);
  41.   out:=copy(stream1,4,2);
  42.   if copy(out,1,1)='0' then delete(out,1,1);
  43.   val(out,day,cd);
  44.   out:=copy(stream1,7,2);
  45.   if copy(out,1,1)='0' then delete(out,1,1);
  46.   val(out,year,cd);
  47.   jnum:=jul(month,day,year);
  48.   str(jnum:10:0,out);
  49.   val(out,internal1,cd);
  50.   out:=copy(stream2,1,2);
  51.   if copy(out,1,1)='0' then delete(out,1,1);
  52.   val(out,month,cd);
  53.   out:=copy(stream2,4,2);
  54.   if copy(out,1,1)='0' then delete(out,1,1);
  55.   val(out,day,cd);
  56.   out:=copy(stream2,7,2);
  57.   if copy(out,1,1)='0' then delete(out,1,1);
  58.   val(out,year,cd);
  59.   jnum:=jul(month,day,year);
  60.   str(jnum:10:0,out);
  61.   val(out,internal2,cd);
  62.   _retval:=internal1-internal2;
  63. end;
  64.  
  65. begin
  66.   check_date('01-01-95','01-01-94');
  67.   writeln('The # of days inbetween is = ',_retval);
  68. end.
  69.